package com.wangzhixuan.commons.utils;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class FileUtil {
	
	public static List<File> getFileList(String path){
		List<File> filelist=new  ArrayList<File>();
		File file=new File(path);
		if(!file.exists()){
			return null;
		}
		
		if(file.isFile()){
			filelist.add(file);
			return filelist;
		}
		
		File[] files=file.listFiles();
		for(File temp:files){
			if(temp.isDirectory()){
				List<File> tempfilelist=getFileList(temp.getAbsolutePath());
				filelist.addAll(tempfilelist);
			}else{
				filelist.add(temp);
			}
		}
		return filelist;
	}
	
	

	 public static String [] getFileName(String path)
	    {
	        File file = new File(path);
	        String [] fileName = file.list();
	        return fileName;
	    }
	    public static void getAllFileName(String path,ArrayList<String> fileName)
	    {
	        File file = new File(path);
	        File [] files = file.listFiles();
	        String [] names = file.list();
	        if(names != null)
	        	fileName.addAll(Arrays.asList(names));
	        for(File a:files)
	        {
	            if(a.isDirectory())
	            {
	                getAllFileName(a.getAbsolutePath(),fileName);
	            }
	        }
	    }
	    public static void main(String[] args){
	    	getFileList("F:\\fun");
	    	/*
	        String [] fileName = getFileName("F:\\fun");
	        for(String name:fileName)
	        {
	            System.out.println(name);
	        }
	        System.out.println("--------------------------------");
	        ArrayList<String> listFileName = new ArrayList<String>(); 
	        getAllFileName("F:\\fun",listFileName);
	        for(String name:listFileName)
	        {
	            System.out.println(name);
	        }
	        */
	         
	    }

}
